package com.sy.controller;

import com.sy.bean.EnterpriseCategory;
import com.sy.bean.query.EnterpriseCategoryTree;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.service.EnterpriseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "企业类目")
@RequestMapping("/api")
public class EnterpriseCategoryController extends BaseController {
    @Autowired
    EnterpriseCategoryService enterpriseCategoryService;

    @ApiOperation("保存类别")
    @PostMapping("/category")
    public ResultBean save(@RequestBody EnterpriseCategory enterpriseCategory) {
        int rs = enterpriseCategoryService.save(enterpriseCategory);
        return gotoResult(rs, "保存");
    }

    @ApiOperation("删除类别")
    @DeleteMapping("/category")
    public ResultBean delete(@RequestParam(value = "id") int id) {
        int rs = enterpriseCategoryService.delete(id);
        return gotoResult(rs, "删除");
    }

    @ApiOperation("修改类别")
    @PutMapping("/category")
    public ResultBean update(EnterpriseCategory enterpriseCategory) {
        int rs = enterpriseCategoryService.update(enterpriseCategory);
        return gotoResult(rs, "修改");
    }

    @ApiOperation("类别列表")
    @GetMapping("/category")
    public ResultBean<EnterpriseCategory> query() {
        List<EnterpriseCategory> list = enterpriseCategoryService.query();
        return success("类别列表", list);
    }

    @ApiOperation("类别列表树")
    @GetMapping("/category/tree")
    public ResultBean<EnterpriseCategoryTree> queryTree() {
        List<EnterpriseCategoryTree> list = enterpriseCategoryService.queryTree();
        return success("类别列表树", list);
    }
}
